package com.lagou.mysql;

import org.apache.commons.dbutils.DbUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class employeeTest {
    public static void main(String[] args) {
        Connection connection = DBUtils.getConnections();
        String query = "select * from employee where NAME = ? and gender = ?";
        try {
            PreparedStatement ps = connection.prepareStatement(query);
            ps.setString(1, "小美");
            ps.setString(2, "女");

            ResultSet resultSet = ps.executeQuery();
            if (resultSet.next()) {
                String name = resultSet.getString("NAME");
                String gender = resultSet.getString("gender");
                System.out.println("Name:" + name + " Gender:" + gender);
            } else {
                System.out.println("None");
            }
            DBUtils.close(connection, ps);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
